import openpyxl,pytest
from selenium import webdriver
from Base import Base

@pytest.fixture()
def driver():
    driver = webdriver.Edge()
    yield driver
    driver.quit()

def test_01(driver):
    work = openpyxl.load_workbook('jiuxian.xlsx')
    excel = work['Sheet1']
    base = Base(driver)
    for row in excel.iter_rows(min_row=2,values_only=True):
        action = row[2]
        p = {}
        if action == 'open_url':
            p['url'] = row[5]

        elif action in ['send_keys','click']:
            p['loc'] = [row[3],row[4]]
            if action == 'send_keys':
                p['info'] = row[5]

        elif action == 'sleep':
            p['s'] = row[5]

        method = getattr(base,str(action))
        method(**p)


def test_02(driver):
    test_01(driver)
    work = openpyxl.load_workbook('jiuxian.xlsx')
    excel = work['Sheet2']
    base = Base(driver)
    for row in excel.iter_rows(min_row=2, values_only=True):
        action = row[2]
        p = {}

        if action in ['send_keys', 'click']:
            p['loc'] = [row[3], row[4]]
            if action == 'send_keys':
                p['info'] = row[5]

        elif action == 'sleep':
            p['s'] = row[5]

        elif action == 'new_window':
            p['n'] = row[5]
        method = getattr(base, str(action))
        method(**p)

if __name__ == '__main__':
    pytest.main()